Interactive Python: a command shell for interactive computing, originally developed for Python but now also supports other languages



install

pip install ipython

launch

ipython

features

tab completion


magic

timeit

  • default is 1000 loops
%%timeit -n 100
# code goes here

other

  • %precision 2 - set floating point precision for printing to 2.d.p.

extensions

sql

%load_ext sql
%sql select * from mytable limit 10

Use python variables

value = 42
%sql select * from table where var = :value

Assign results of queries to python variables

result = %sql select * from mytable limit 10
print(result.DataFrame())

Import from csv

import pandas as pd
mydata = pd.read_csv('https://....csv')
%sql PERSIST mydata
%sql SELECT * FROM mydata limit 5;